package cn.common.exceptions;

/**
 * Copyright
 *
 * @Author WuHuang
 * @Date 2022/12/22
 */

/**
 * 云mall，运行时异常
 *
 * @author mantou
 */
public class TRetailRuntimeException extends RuntimeException {
    /**
     * 错误码
     */
    protected final ErrorCode errorCode;

    public TRetailRuntimeException() {
        super(BaseErrorCode.UNSPECIFIED.getDescription());
        this.errorCode = BaseErrorCode.UNSPECIFIED;
    }

    public TRetailRuntimeException(final ErrorCode errorCode) {
        super(errorCode.getDescription());
        this.errorCode = errorCode;
    }

    /**
     * 指定详细描述构造通用异常
     *
     * @param detailedMessage 详细描述
     */
    public TRetailRuntimeException(final String detailedMessage) {
        super(detailedMessage);
        this.errorCode = FailErrorCode.build(detailedMessage);
    }

    /**
     * 指定导火索构造通用异常
     *
     * @param t 导火索
     */
    public TRetailRuntimeException(final Throwable t) {
        super(t);
        this.errorCode = FailErrorCode.build(t.getMessage());
    }

    /**
     * 构造通用异常
     *
     * @param errorCode       错误码
     * @param detailedMessage 详细描述
     */
    public TRetailRuntimeException(final ErrorCode errorCode, final String detailedMessage) {
        super(detailedMessage);
        this.errorCode = FailErrorCode.build(errorCode.getCode(), detailedMessage);
    }

    /**
     * 构造通用异常
     *
     * @param errorCode 错误码
     * @param t         导火索
     */
    public TRetailRuntimeException(final ErrorCode errorCode, final Throwable t) {
        super(errorCode.getDescription(), t);
        this.errorCode = errorCode;
    }

    /**
     * 构造通用异常
     *
     * @param detailedMessage 详细描述
     * @param t               导火索
     */
    public TRetailRuntimeException(final String detailedMessage, final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = FailErrorCode.build(detailedMessage);
    }


    /**
     * 构造通用异常
     *
     * @param errorCode       错误码
     * @param detailedMessage 详细描述
     * @param t               导火索
     */
    public TRetailRuntimeException(final ErrorCode errorCode, final String detailedMessage,
                                   final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = FailErrorCode.build(errorCode.getCode(), detailedMessage);
    }

    public TRetailRuntimeException(String code, String msg) {
        super(msg);
        this.errorCode = FailErrorCode.build(code, msg);
    }


    /**
     * Getter method for property <tt>errorCode</tt>.
     *
     * @return property value of errorCode
     */
    public ErrorCode getErrorCode() {
        return errorCode;
    }
}

